package com.atguigu.gmall.cart.service;

import com.atguigu.gmall.cart.mapper.CartInfoMapper;
import com.atguigu.gmall.model.cart.CartInfo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @author 李旭
 * @date 2021/10/18 15:56
 * @Description:
 */
@Service
public class CartInfoSyncServiceImpl implements CartInfoSyncService {
    @Autowired
    private CartInfoMapper cartInfoMapper;
    //异步保存DB数据
    @Override
    @Async
    public void insertCartInfo(CartInfo cartInfo) {
        System.out.println("子线程异步保存DB数据：" + Thread.currentThread().getName());
        cartInfoMapper.insert(cartInfo);
    }

    @Override
    @Async
    public void updateCartInfo(CartInfo cartInfo) {
        System.out.println("子线程异步保存DB数据：" + Thread.currentThread().getName());
        cartInfoMapper.update(cartInfo,new QueryWrapper<CartInfo>()
           .eq("user_id",cartInfo.getUserId())
           .eq("sku_id",cartInfo.getSkuId()));
    }
}
